home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASMWIZ14.ZIP / ASMWIZ.DOC < prev    next >
Text File  |  1991-09-09  |  42KB  |  1,009 lines

  1.                         The Assembly Wizard's Library                   page 1
  2.  
  3.             ASMWIZ  Copyright (c) 1990-1991  Thomas G. Hanlin III
  4.  
  5.  
  6.  
  7. This is ASMWIZ, a library of assembly language routines for assembly language
  8. programmers.  It is copyrighted and may be distributed only under the
  9. following conditions:
  10.  
  11.    1) No fee of over $10.00 may be charged for distribution.  This
  12.       restriction applies only to physical copies and is not meant to prevent
  13.       distribution by telecommunication.
  14.  
  15.    2) All ASMWIZ files must be distributed together in original, unaltered
  16.       form.  This includes ASMWIZ.DOC, ASMWIZ.MAN, ASMWIZ.NEW, ASMWIZ.XRF,
  17.       BIBLIO.TXT, EXAMPLE.ASM, EXAMPLE.CGA, EXAMPLE.COM, EXAMPLE.EGA,
  18.       EXECOM.COM, FILES.LST, PRODUCT.TXT, REGISTER.TXT, 8CREATE.BAT,
  19.       OCREATE.BAT, MCREATE.BAT, and TCREATE.BAT.
  20.  
  21.    3) BBSes *MAY NOT* add advertisement files to my archive!!!  Goldurnit,
  22.       this should go without saying.  Shame on sysops who do this!
  23.  
  24. You use this library at your own risk.  It has been tested by me on my own
  25. computer, but I will not assume any responsibility for any problems which
  26. ASMWIZ may cause you.  If you do encounter a problem, please let me know
  27. about it, and I will do my best to verify and repair the error.
  28.  
  29. It is expected that if you find ASMWIZ useful, you will register your copy.
  30. This entitles you to receive the latest version of ASMWIZ, complete with full
  31. source code.  The source code is designed for the Microsoft Macro Assembler
  32. (MASM) v6.0 and may require minor modifications to assemble with OPTASM,
  33. TASM, or older versions of MASM.
  34.  
  35. The ASMWIZ library was designed for use with small assembly programs and is
  36. compatible with the creation of COM files.  All CALLs are of the NEAR
  37. variety.  If there is sufficient interest, a FAR model will also be made.
  38.  
  39. For an example of how to set up your program to access the ASMWIZ library,
  40. how to LINK the routines, and so forth, see the EXAMPLE.ASM, EXAMPLE.COM,
  41. and ?CREATE.BAT files (FILES.LST tells you which batch file to use with which
  42. assembler; there are versions for A86, MASM, OPTASM, QuickASM, and TASM).
  43.  
  44. The new EXAMPLE.ASM and .BAT files are due to the efforts of a kind gentleman
  45. whose name I have regrettably lost.  If you're reading this, sir, please get
  46. in touch with me!
  47.  
  48. Note that DOS-dependent services expect DOS 2.0 or higher versions, unless
  49. otherwise specified.
  50.  
  51. Services to be added in future versions include additional mouse handling,
  52. keyboard control and input services, expanded and extended memory support,
  53. background music, ANSI emulation, communications, and much more.  If there is
  54. something in particular that you'd like to see, please let me know about it.
  55.  
  56.                               Table of Contents                         page 2
  57.  
  58.  
  59.  
  60.  Overview and Legal Info ................................................ 1
  61.  
  62.  Base Conversions ....................................................... 3
  63.  
  64.  Exception Handling ..................................................... 4
  65.  
  66.  Delays and Countdowns .................................................. 5
  67.  
  68.  File Handling .......................................................... 6
  69.  
  70.  Filename Manipulation .................................................. 8
  71.  
  72.  Long Integer Math ...................................................... 9
  73.  
  74.  Memory Services ....................................................... 10
  75.  
  76.  Mouse Services ........................................................ 11
  77.  
  78.  Sound and Music ....................................................... 12
  79.  
  80.  String Services ....................................................... 13
  81.  
  82.  Telecommunications .................................................... 14
  83.  
  84.  Time and Date ......................................................... 15
  85.  
  86.  Video Services ........................................................ 16
  87.  
  88.  Miscellaneous Services ................................................ 23
  89.  
  90.  Error Codes ........................................................... 24
  91.  
  92.                                Base Conversions                         page 3
  93.  
  94.  
  95.  
  96. The Base Conversion Services provide the ability to convert back and forth
  97. between a number and its ASCIIZ representation.  Any base from 2-36 may be
  98. employed, so these routines encompass binary, decimal, hex and octal
  99. conversions.  Services are provided for integers and long integers, both
  100. signed and unsigned.
  101.  
  102.  
  103. The following services are available:
  104.  
  105.    BC_ASC2INT    convert an ASCIIZ string to an unsigned integer
  106.                        BL <-- base from which to convert
  107.                     DS:SI <-- ptr to string
  108.                     -------
  109.                        AX = unsigned integer
  110.  
  111.    BC_ASC2LONG   convert an ASCIIZ string to an unsigned long integer
  112.                        BL <-- base from which to convert
  113.                     DS:SI <-- ptr to string
  114.                     -------
  115.                     DX,AX = unsigned long integer
  116.  
  117.    BC_ASC2SINT   convert an ASCIIZ string to a signed integer
  118.                        BL <-- base from which to convert
  119.                     DS:SI <-- ptr to string
  120.                     -------
  121.                        AX = signed integer
  122.  
  123.    BC_ASC2SLONG  convert an ASCIIZ string to a signed long integer
  124.                        BL <-- base from which to convert
  125.                     DS:SI <-- ptr to string
  126.                     -------
  127.                     DX,AX = signed long integer
  128.  
  129.    BC_INT2ASC    convert an unsigned integer to an ASCIIZ string
  130.                        AX <-- unsigned integer
  131.                        BL <-- base to which to convert
  132.                     ES:DI <-- ptr to string buffer (recommend 17 bytes)
  133.  
  134.    BC_LONG2ASC   convert an unsigned long integer to an ASCIIZ string
  135.                     DX,AX <-- unsigned long integer
  136.                        BL <-- base to which to convert
  137.                     ES:DI <-- ptr to string buffer (recommend 33 bytes)
  138.  
  139.    BC_SINT2ASC   convert a signed integer to an ASCIIZ string
  140.                        AX <-- signed integer
  141.                        BL <-- base to which to convert
  142.                     ES:DI <-- ptr to string buffer (recommend 18 bytes)
  143.  
  144.    BC_SLONG2ASC  convert a signed long integer to an ASCIIZ string
  145.                     DX,AX <-- signed long integer
  146.                        BL <-- base to which to convert
  147.                     ES:DI <-- ptr to string buffer (recommend 34 bytes)
  148.  
  149.                                 Exception Handling                      page 4
  150.  
  151.  
  152.  
  153. The Exception Handling Services allow your program to take control over
  154. exception conditions.  This covers critical errors and control-break /
  155. control-c handling.
  156.  
  157. The critical error handler gives you the ability to recover from critical
  158. errors, which would otherwise cause the infamous "A>bort, R>etry, I>gnore"
  159. prompt.
  160.  
  161. The break handler allows your program to ignore the Control-C and
  162. Control-Break keys or to process them in an orderly manner.  This is vital if
  163. you are using any of the ASMWIZ services which need to be shut down before
  164. the program terminates.  Up to eight procedures can be called when ^Break or
  165. ^C are used (they will be ignored if you turn off ^Break / ^C).
  166.  
  167.  
  168. The following services are available:
  169.  
  170.  
  171.    EH_INITCRIT   initialize the critical error handler
  172.  
  173.    EH_CRITERR    check for a critical error
  174.  
  175.    EH_CRITDONE   terminates the critical error handler
  176.  
  177.    EH_INITBREAK  initialize the ^C / ^Break handler
  178.  
  179.    EH_ADDBREAK   add a procedure to be called on ^C / ^Break
  180.                        DX <-- procedure offset (from CS: near code is assumed)
  181.  
  182.    EH_SETBREAK   allow or ignore ^C and ^Break
  183.                        AL <-- 0 to ignore, 1 to allow
  184.  
  185.    EH_SUBBREAK   remove a procedure to be called on ^C / ^Break
  186.                        DX <-- procedure offset (from CS: near code is assumed)
  187.  
  188.  
  189.                              Delays and Countdowns                      page 5
  190.  
  191.  
  192.  
  193. The Delay Services are for those times when you want the computer to sit
  194. around doing nothing for a while.  Delays of various timing resolution are
  195. available for anything from small to large waits.
  196.  
  197. Notes on the 100th-second delay and countdown services:
  198.    Since MD_DONE must be called before the program terminates, you should use
  199. the EH_ADDBREAK service to insure that MD_DONE is called if Control-Break or
  200. Control-C are permitted to abort the program.
  201.    Timers 0-1 may be used by ASMWIZ itself for various services.
  202.    See ASMWIZ.MAN for more details on the 100th-second delay services.
  203.  
  204.  
  205. The following services are available:
  206.  
  207.  
  208.    MD_DELAY      delay for a number of 100ths of seconds
  209.                        CX <-- delay (0-32767)
  210.  
  211.    MD_DONE       terminate 100th-second delay handler
  212.  
  213.    MD_GETTIMER   get a delay count
  214.                        AL <-- timer number (0-3)
  215.                     -------
  216.                        CX = delay * 2 (0-65534)
  217.  
  218.    MD_INIT       initialize 100th-second delay handler
  219.  
  220.    MD_SETTIMER   set a delay count
  221.                        AL <-- timer number (0-3)
  222.                        CX <-- delay (0-32767)
  223.  
  224.    MD_TICK       delay for a number of clock ticks (18ths of seconds)
  225.                        CX <-- delay (0-65535)
  226.  
  227.                                 File Handling                           page 6
  228.  
  229.  
  230.  
  231. The File Handling Services provide a comprehensive and powerful set of
  232. routines for file handling.  The usual open file, read/write, file pointer
  233. manipulation, and close file operations are supported, of course.  New
  234. conveniences include automatic network support (file sharing is used if the
  235. DOS version is high enough), optional input buffering for extra speed, and
  236. special support for text files.  A future version of ASMWIZ will allow you to
  237. have an indefinite number of files open at a time, using any DOS version.
  238. Critical error handling is supported via the Exception Handling Services.
  239.  
  240. These services return with the carry flag set if there is an error.  In that
  241. case, the AX register returns the error code.  Note that, unlike most other
  242. services, the file services are allowed to change the AX register regardless
  243. of whether an error occurred.
  244.  
  245.  
  246. The following services are available:
  247.  
  248.    DF_CLOSE      close a file
  249.                        BX <-- (virtual) file handle
  250.  
  251.    DF_DONE       terminate the File Handling Services (closes all open files)
  252.  
  253.    DF_FLUSH      flush a file to disk (updates disk directory)
  254.                        BX <-- (virtual) file handle
  255.  
  256.    DF_GETTIME    get file time/date stamp
  257.                        BX <-- (virtual) file handle
  258.                     -------
  259.                        AX = time
  260.                        DX = date
  261.  
  262.    DF_HANDLE     get DOS file handle, given virtual file handle
  263.                        BX <-- (virtual) file handle
  264.                     -------
  265.                        BX = (DOS) file handle
  266.  
  267.    DF_INIT       initialize the File Handling Services
  268.                        DX <-- 0
  269.  
  270.    DF_LOCATE     set file read/write pointer
  271.                        BX <-- (virtual) file handle
  272.                        CL <-- use 0 for offset from start, 1 for offset from
  273.                               current position, 2 for offset from end of file
  274.                     DX,AX <-- offset
  275.  
  276.                                 File Handling                           page 7
  277.  
  278.  
  279.  
  280.    DF_OPEN       open a file for access
  281.                        AX <-- set bit 0 for read, bit 1 for write, bit 2
  282.                               for create, bit 3 for text file, others zero
  283.                     DS:DX <-- pointer to ASCIIZ filename
  284.                        CX <-- length of input buffer (zero if no buffer)
  285.                     ES:SI <-- pointer to input buffer, if any
  286.                     -------
  287.                        BX = (virtual) file handle
  288.  
  289.    DF_READ       read from a file
  290.                        BX <-- (virtual) file handle
  291.                        CX <-- bytes to read (for text files, is max bytes)
  292.                     DS:DX <-- pointer to read buffer
  293.                     -------
  294.                        AX = bytes actually read (if NC and not text mode)
  295.  
  296.    DF_TIME       set file time/date stamp
  297.                        BX <-- (virtual) file handle
  298.                        AX <-- time
  299.                        DX <-- date
  300.  
  301.    DF_WHERE      get file read/write pointer
  302.                        BX <-- (virtual) file handle
  303.                     -------
  304.                     DX,AX = offset
  305.  
  306.    DF_WRITE      write to a file
  307.                        BX <-- (virtual) file handle
  308.                        CX <-- bytes to write (for text files, is ignored)
  309.                     DS:DX <-- pointer to write buffer
  310.  
  311.                             Filename Manipulation                       page 8
  312.  
  313.  
  314.  
  315. The Filename Manipulation Services allow various operations on filenames
  316. which make it possible to duplicate the capabilities of the DOS command shell.
  317. This includes finding a file which matches a specified pattern, forcing a
  318. filename to match a given pattern, splitting a filespec into its component
  319. parts, and completing a (possibly partial) filespec.
  320.  
  321.  
  322. The following services are available:
  323.  
  324.    FI_COMPLETE   complete a filespec from a (possibly) partial specification
  325.                     DS:SI <-- filename (may have drive, dir, "." or "..", etc)
  326.                     DS:BX <-- default extension to be added (sans ".")
  327.                     ES:DI <-- 80-byte buffer for result
  328.                     -------
  329.                     Flags = CY if the filespec is not valid
  330.                             NC if it went ok
  331.  
  332.    FI_MATCH      see if a filename matches a specified pattern
  333.                     DS:SI <-- pattern (may contain wildcards)
  334.                     ES:DI <-- filename (may not contain drive or path specs)
  335.                     -------
  336.                     Flags = ZF if the filename matches the pattern
  337.                             NZ if the filename doesn't match the pattern
  338.  
  339.    FI_PATTERN    push a filename through a pattern specification
  340.                     DS:SI <-- filename (no drive or directory allowed)
  341.                     DS:BX <-- pattern
  342.                     ES:DI <-- 13-byte buffer for results
  343.                     -------
  344.                     Flags = CY for some filename/pattern errors
  345.                             NC if it went ok
  346.  
  347.    FI_SPLIT      split a path specification into drive, directory, filename
  348.                     DS:SI <-- path spec
  349.                     ES:DI <-- 80-byte buffer for results
  350.  
  351.                               Long Integer Math                         page 9
  352.  
  353.  
  354.  
  355. The Long Integer Math Services provide support for the basic arithmetic
  356. operations on unsigned long integers.  They allow you to add two 32-bit
  357. integers, subtract one 32-bit integer from another, multiply two 32-bit
  358. integers (giving a 64-bit result), and divide a 63-bit integer by a 32-bit
  359. integer (giving a 32-bit result and 32-bit remainder).
  360.  
  361. Since 32-bit integers are rather unwieldy unless you're using an 80386 or
  362. above (in which case you don't need these services anyway), the numbers are
  363. passed back and forth through a buffer in memory.
  364.  
  365.  
  366. The following services are available:
  367.  
  368.    MA_ADD32      add two unsigned long integers
  369.                     DS:SI   <-- first operand
  370.                     DS:SI+4 <-- second operand
  371.                     -------
  372.                     DS:SI+8 = result
  373.  
  374.    MA_DIV32      divide an unsigned 63-bit integer by an unsigned long integer
  375.                     DS:SI   <-- dividend (64 bits: high bit must be zero)
  376.                     DS:SI+8 <-- divisor (unsigned long integer)
  377.                     -------
  378.                     DS:SI+12 = quotient (unsigned long integer)
  379.                     DS:SI+16 = remainder (unsigned long integer)
  380.  
  381.    MA_MUL32      multiply two unsigned long integers
  382.                     DS:SI   <-- first operand
  383.                     DS:SI+4 <-- second operand
  384.                     -------
  385.                     DS:SI+8 = result (unsigned very long integer: 64 bits)
  386.  
  387.    MA_SUB32      subtract one unsigned long integer from another
  388.                     DS:SI   <-- first operand
  389.                     DS:SI+4 <-- second operand
  390.                     -------
  391.                     DS:SI+8 = result
  392.  
  393.                                Memory Services                          page 10
  394.  
  395.  
  396.  
  397. The Memory Services provide low-level routines for memory manipulation.  They
  398. allow you to manipulate addresses, provide a "smart" block move service that
  399. automatically handles overlaps between source and destination areas, and
  400. allows you to save or restore blocks of memory in BASIC's BSAVE format.
  401.  
  402. Among the address manipulation services are routines to convert an address to
  403. have the smallest possible segment and highest possible offset (or vice
  404. versa) to allow REP operations to always handle up to 65,519 bytes without
  405. wrapping within the segment.  This can also be useful in file operations.
  406.  
  407.  
  408. The following services are available:
  409.  
  410.    ME_BINFO      get information about a BSAVE-format file
  411.                     DS:DX <-- pointer to ASCIIZ filename
  412.                     -------
  413.                     ES:SI = segment:offset
  414.                        CX = image size (bytes)
  415.                     Flags = CY if unable to load file; AX is error code
  416.  
  417.    ME_BLOAD      load a BSAVE-format file into memory
  418.                     DS:DX <-- pointer to ASCIIZ filename
  419.                     -------
  420.                     Flags = CY if unable to load file; AX is error code
  421.  
  422.    ME_BSAVE      save a block of memory to a BSAVE-format file
  423.                     DS:DX <-- pointer to ASCIIZ filename
  424.                     ES:SI = segment:offset
  425.                        CX = image size (bytes)
  426.                     -------
  427.                     Flags = CY if unable to save memory; AX is error code
  428.  
  429.    ME_HIGHOFS    convert an address to have the lowest segment & highest offset
  430.                     DX:AX <-- segment:offset
  431.                     -------
  432.                     DX:AX = converted segment:offset
  433.  
  434.    ME_LOWOFS     convert an address to have the highest segment & lowest offset
  435.                     DX:AX <-- segment:offset
  436.                     -------
  437.                     DX:AX = converted segment:offset
  438.  
  439.    ME_MOVE       move a block of memory without overlap conflicts
  440.                     DS:SI <-- source segment:offset
  441.                     ES:DI <-- destination segment:offset
  442.                        CX <-- bytes to move (0 - 65,519)
  443.  
  444.                                 Mouse Services                          page 11
  445.  
  446.  
  447.  
  448. The Mouse Services provide a simple set of functions for dealing with
  449. Microsoft-compatible mouse devices.  You may see if a mouse exists, control
  450. the mouse cursor, and get information about the mouse buttons.
  451.  
  452.  
  453. The following services are available:
  454.  
  455.    MO_HIDECURSOR hide the mouse cursor
  456.  
  457.    MO_INIT       see if a mouse is installed (and if so, how many buttons)
  458.                     -------
  459.                        AL = number of buttons on the mouse (zero if no mouse)
  460.  
  461.    MO_LOCATE     set the mouse cursor location
  462.                        DH <-- row (1-25)
  463.                        DL <-- column (1-80)
  464.  
  465.    MO_RANGE      set the mouse cursor range
  466.                        CH <-- top row (1-25)
  467.                        CL <-- leftmost column (1-80)
  468.                        DH <-- bottom row (1-25)
  469.                        DL <-- rightmost column (1-80)
  470.  
  471.    MO_SHOWCURSOR show the mouse cursor
  472.  
  473.    MO_WHERE      get the mouse cursor location and button states
  474.                     -------
  475.                        AL = left button (0 = not pressed, 1 = pressed)
  476.                        AH = right button (0 = not pressed, 1 = pressed)
  477.                        DH = row (1-25)
  478.                        DL = column (1-80)
  479.  
  480.                                Sound and Music                          page 12
  481.  
  482.  
  483.  
  484. The Sound and Music Services provide the ability to generate sound effects
  485. and music.  The current service is rather on the primitive side.  It will be
  486. supplemented by a background (interrupt-driven) music command language in a
  487. future version of ASMWIZ.
  488.  
  489.  
  490. The following services are available:
  491.  
  492.    MU_SOUND      produce a sound of a specified duration and frequency
  493.                     AX <-- frequency (Hertz; about 50-4000 is useful)
  494.                     DX <-- duration  (18ths of seconds)
  495.  
  496.                            String Services (ASCIIZ)                     page 13
  497.  
  498.  
  499.  
  500. The ASCIIZ String Services provide a wide assortment of services for dealing
  501. with null-terminated strings.
  502.  
  503. Note that, although many of the string services are designed to place the
  504. result of processing a first string into a second string, it is not actually
  505. necessary to use two string buffers.  The services are designed so that you
  506. can place the results back into the original string buffer by using the same
  507. address for both strings.
  508.  
  509.  
  510. The following routines are included amongst the ASCIIZ String Services:
  511.  
  512.    S0_COMPARE    compares two strings
  513.                     DS:SI <-- first string
  514.                     ES:DI <-- second string
  515.                     -------
  516.                     Flags = ZF if equal, NZ if not equal
  517.                             CY if first < second, NC if first >= second
  518.  
  519.    S0_DUPE       forms a string by duplicating a character
  520.                     ES:DI <-- result string
  521.                        AL <-- character to duplicate
  522.                        CX <-- number of times to repeat the character
  523.  
  524.    S0_LEFT       copies a specified section from the left of a string
  525.                     DS:SI <-- source string
  526.                        CX <-- number of characters to copy
  527.                     ES:DI <-- result string
  528.  
  529.    S0_LENGTH     gets the length of a string (excluding the null terminator)
  530.                     DS:SI <-- string
  531.                     -------
  532.                        CX = string length
  533.  
  534.    S0_LOCASE     converts a string to lowercase (international)
  535.                     DS:SI <-- source string
  536.                     ES:DI <-- result string
  537.  
  538.    S0_MID        copies a specified section of a string
  539.                     DS:SI <-- source string
  540.                        DX <-- where to start copying from (1-xx)
  541.                        CX <-- how many characters to copy
  542.                     ES:DI <-- result string
  543.  
  544.    S0_RIGHT      copies a specified section from the right of a string
  545.                     DS:SI <-- source string
  546.                        CX <-- number of characters to copy
  547.                     ES:DI <-- result string
  548.  
  549.    S0_TRIM       trims the "white space" (blanks and control characters) from
  550.                  either side (or both sides) of a string
  551.                     DS:SI <-- source string
  552.                        AL <-- set bit 0 to trim the left, bit 1 for right
  553.                     ES:DI <-- result string
  554.  
  555.    S0_UPCASE     converts a string to uppercase (international)
  556.                     DS:SI <-- source string
  557.                     ES:DI <-- result string
  558.  
  559.                               Telecommunications                        page 14
  560.  
  561.  
  562.  
  563. The Telecommunications Services provide functions that are useful for
  564. telecommunications.  At the moment, this is limited to services that aid in
  565. performing file transfers and similar functions.
  566.  
  567.  
  568. The following routines are included amongst the Telecommunications Services:
  569.  
  570.    TC_CHKSUM     calculate the Xmodem/Ymodem checksum of a block of data
  571.                     DS:SI <-- pointer to a data block
  572.                        CX <-- length of data block (in bytes)
  573.                     -------
  574.                        AX = checksum
  575.  
  576.    TC_CRC        calculate the Xmodem/Ymodem CRC of a block of data
  577.                     DS:SI <-- pointer to a data block
  578.                        CX <-- length of data block (in bytes)
  579.                     -------
  580.                        AX = resulting CRC
  581.  
  582.                             Time and Date Services                      page 15
  583.  
  584.  
  585.  
  586. The Time and Date Services provide international date handling.  Based on the
  587. country code given it by DOS, these services return strings that represent
  588. the current time or date in the appropriate format for that country.
  589.  
  590. These services provide a simple way to make your software work properly on
  591. any computer anywhere, across the world.
  592.  
  593. See the COUNTRY entry under CONFIG.SYS in your DOS manual for more details.
  594. Note that DOS version 3.0 or greater is required to insure that the date and
  595. time delimiters are appropriate.  Otherwise, the date and time formats will
  596. still be correct, but the delimiters used will be assumed to be "-" for the
  597. date and ":" for the time.  With DOS versions before 3.0, the time will be
  598. presented in 12-hour (am/pm) format.
  599.  
  600.  
  601. The following routines are included amongst the Time and Date Services:
  602.  
  603.    TD_GETDATE    get the current date as an ASCIIZ string
  604.                  DS:DX <-- pointer to a buffer (minimum 11 bytes)
  605.                     AL <-- 0 for 2-digit year, 1 for 4-digit year
  606.  
  607.    TD_GETTIME    get the current date as an ASCIIZ string
  608.                  DS:DX <-- pointer to a buffer (minimum 8 bytes)
  609.  
  610.                                 Video Services                          page 16
  611.  
  612.  
  613.  
  614. Displaying text is something that almost every program will do.  The ASMWIZ
  615. library contains numerous sets of video services which make it easy to use
  616. the display in a consistent manner.
  617.  
  618. The display services are divided into five sets of routines, each of which
  619. provides similar capabilities:
  620.  
  621.    DV    DOS-level services
  622.    BV    BIOS-level services
  623.    MV    Machine-level services for text modes
  624.    CG    Machine-level services for CGA graphics modes
  625.    HG    Machine-level services for Hercules graphics mode
  626.  
  627. The DOS services provide the maximum level of compatibility.  They are also
  628. the slowest of the video services and the least flexible.  The main practical
  629. advantage of using DOS services is that they allow redirection, so the output
  630. of your program can be sent to a file, a printer, or a serial port as well as
  631. to the display.  Since DOS itself has only minimal video support, you will
  632. need to make sure an ANSI driver is installed before using these services.
  633. See your DOS manual on ANSI.SYS for more information if you need it.
  634.  
  635. The BIOS services provide a very good level of compatibility.  They are
  636. faster and more flexible than the DOS services.  Like the DOS services, these
  637. routines are quite likely to work on nonstandard displays.
  638.  
  639. The machine-level services are the least compatible.  They will work on any
  640. standard PC clone, but not on semi-compatible hardware or with nonstandard
  641. display devices.  In return for this disadvantage, these services are much
  642. faster than the other services and provide a great deal more flexibility.
  643. Only the machine-level services support Hercules graphics mode.
  644.  
  645.                                 Video Services                          page 17
  646.                               Text Display Speeds
  647.  
  648.  
  649.  
  650. Speed tests were conducted on an 8088 machine with a Phoenix BIOS, running
  651. MS-DOS 3.30.  "Your mileage may differ."  The tests were conducted on how
  652. quickly strings could be printed to the display.
  653.  
  654. Speeds are listed relative to the slowest display method (DOS services).
  655.  
  656.  
  657.  
  658.                     +-----------+-----------+-----------+-----------+
  659.                     | DV_STROUT | BV_STROUT | MV_STROUT | CG_STROUT |
  660.        +------------+-----------+-----------+-----------+-----------+
  661.        | Mode 3     |           |           |           |           |
  662.        | text mode  |    100%   |    162%   |    572%   |    n/a    |
  663.        +------------+-----------+-----------+-----------+-----------+
  664.        | Mode 4     |           |           |           |           |
  665.        | CGA lo-res |    100%   |    114%   |    n/a    |    180%   |
  666.        +------------+-----------+-----------+-----------+-----------+
  667.        | Mode 6     |           |           |           |           |
  668.        | CGA hi-res |    100%   |    122%   |    n/a    |    204%   |
  669.        +------------+-----------+-----------+-----------+-----------+
  670.  
  671.  
  672.  
  673. From this chart, you can see that using BIOS display services is 14% - 62%
  674. faster than using DOS services.  Using machine-level services is 80% - 472%
  675. faster than using DOS services, and about 60% - 250% faster than using BIOS
  676. services.
  677.  
  678. If system compatibility is a major concern, then note that the DOS services
  679. are most compatible, followed by the BIOS services and then the machine-level
  680. services.  The price you pay for compatibility is speed and flexibility.  The
  681. machine-level services are the fastest and most flexible, followed by the
  682. BIOS services and then the DOS services.
  683.  
  684.                                 Video Services                          page 18
  685.                           General Video Information
  686.                   (not applicable to Hercules graphics mode)
  687.  
  688.  
  689.  
  690. For all text routines, color/attributes are encoded as a single byte value:
  691.  
  692. bit:    7   6   5   4   3   2   1   0
  693.       +---+---+---+---+---+---+---+---+
  694.       | B |  backgnd  | I |  foregnd  |
  695.       +---+---+---+---+---+---+---+---+
  696.  
  697. B:  "blink".  Set if the color is blinking.
  698.  
  699. I:  "intense".  Set if the foreground color is intense (bright or light).
  700.  
  701. backgnd, foregnd:  the actual foreground and background colors.  The bits
  702.     specify the red, green, and blue components of the color, giving the
  703.     following list of colors:
  704.  
  705.        0    black     (if intense, may or may not be displayed as gray)
  706.        1    blue
  707.        2    green
  708.        3    cyan
  709.        4    red
  710.        5    magenta
  711.        6    brown     (if intense, is usually displayed as yellow)
  712.        7    white
  713.  
  714.  
  715. Text in CGA graphics modes is different.  If you use BIOS or DOS services,
  716. you may only specify a foreground color, which may be 0-3.  If you use the
  717. CGA machine-level services, you may specify a background color as well as a
  718. foreground color.  Color encoding is the same as for text mode, with the
  719. exception that there are no "blinking" or "intense" bits, and the color range
  720. is 0-3 instead of 0-7.  The 0-3 range does not follow the above color list
  721. (instead, the colors depend on which CGA palette is in use).
  722.  
  723.  
  724.  
  725. Screen modes are specified as a single byte, as follows:
  726.  
  727.      Mode  Resolu.  Type  Colr  Use        Adapter(s)        Services
  728.  
  729.        0   40x25    b&w     16  text       CGA, EGA, VGA     MV, BV, DV
  730.        1   40x25    color   16  text       CGA, EGA, VGA     MV, BV, DV
  731.        2   80x25    b&w     16  text       CGA, EGA, VGA     MV, BV, DV
  732.  def-  3   80x25    color   16  text       CGA, EGA, VGA     MV, BV, DV
  733.        4   320x200  color    4  graphics   CGA, EGA, VGA     CG, BV, DV
  734.        5   320x200  b&w      4  graphics   CGA, EGA, VGA     CG, BV, DV
  735.        6   640x200  color    2  graphics   CGA, EGA, VGA     CG, BV, DV
  736.  mda-  7   80x25    b&w      -  text       MDA, EGA, VGA     BV
  737.       13   320x200  color   16  graphics   EGA, VGA          BV
  738.       14   640x200  color   16  graphics   EGA, VGA          BV
  739.       15   640x350  mono     -  graphics   EGA, VGA          BV
  740.       16   640x350  color   16  graphics   EGA, VGA          BV
  741.       17   640x480  color    2  graphics   VGA               BV
  742.       18   640x480  color   16  graphics   VGA               BV
  743.       19   320x200  color  256  graphics   VGA               BV
  744.  
  745. BV = BIOS video services             DV = DOS video services
  746. MV = Machine-level text services     CG = Machine-level CGA graphics services
  747.  
  748.                                 Video Services                          page 19
  749.  
  750.  
  751.  
  752. All of the video services share a common nomenclature and calling procedure.
  753. For many of the services, you will have a choice of whether to use DOS, BIOS,
  754. Machine-level (text modes), Machine-level (CGA graphics modes), or
  755. Machine-level (Hercules graphics mode).  The level is specified as a
  756. two-letter code prefix to the routine name, where the codes are as follows:
  757.  
  758.     DV    DOS Video
  759.     BV    BIOS Video
  760.     MV    Machine-level (text mode) Video
  761.     CG    Machine-level (CGA graphics mode) Video
  762.     HG    Machine-level (Hercules graphics mode) Video
  763.  
  764. The routine to display a string using DOS services, for example, is named
  765. DV_STROUT (DOS Video service, String Output).  It usually isn't a good idea
  766. to "mix and match" video services of different types.
  767.  
  768.  
  769. The following services are available:
  770.  
  771.  
  772.     CHROUT      display a character                            BV,DV,MV,CG,HG
  773.                    AL <-- character
  774.  
  775.     CLS         clear the screen and home the cursor           BV,DV,MV,CG,HG
  776.  
  777.     COLOR       set the text color                             BV,DV,MV,CG,HG
  778.                    AL <-- color/attribute
  779.  
  780.     CRLF        display a carriage return and a linefeed       BV,DV,MV,CG,HG
  781.  
  782.     CLEOLN      clear from the cursor to the end of the line   BV,DV,MV,CG,HG
  783.  
  784.     DELCHR      delete the character at the cursor               ,  ,MV,  ,
  785.  
  786.     DELLINE     delete the current line                        BV,dv,MV,  ,
  787.  
  788.     GETCOLOR    get the text color                             BV,  ,MV,CG,HG
  789.                    -------
  790.                    AL = color/attribute
  791.  
  792.     GETMODE     get the current screen mode                    BV,  ,MV,  ,
  793.                    -------
  794.                    AL = mode
  795.  
  796.     FIXCOLOR    whether to convert colors to monochrome        BV,DV,MV,  ,
  797.                    AL <-- whether to convert (0 no, 1 yes)
  798.  
  799.     FRAME       display a window frame                           ,  ,MV,  ,
  800.                    CH,CL <-- upper left corner (row, column)
  801.                    DH,DL <-- lower right corner (row, column)
  802.                    DS:SI <-- frame char. list (-1 to -9 special)
  803.  
  804.                                 Video Services                          page 20
  805.  
  806.  
  807.  
  808.     HIDECURSOR  hide the cursor                                BV,  ,MV,  ,
  809.  
  810.     INIT        initialize the video service routines            ,  ,MV,CG,
  811.  
  812.     INSCHR      insert a space at the cursor                     ,  ,MV,  ,
  813.  
  814.     INSLINE     insert a row at the current line               BV,dv,MV,  ,
  815.  
  816.     LOCATE      set the cursor position                        BV,DV,MV,CG,HG
  817.                    DH <-- row (1-25/43)
  818.                    DL <-- column (1-40/80/90)
  819.  
  820.     MODE        set the screen mode                            BV,DV,MV,CG,HG
  821.                    AL <-- mode (see General Video Info)
  822.  
  823.     POPUP       display a pop-up window                        BV,  ,MV,  ,
  824.                    DS:DX <-- parameter pointer
  825.  
  826.     SAVESIZE    calculate bytes needed to save a screen area     ,  ,MV,  ,
  827.                    -------
  828.                    AL = bytes
  829.  
  830.     SCRREST     restore a saved screen area from a buffer        ,  ,MV,  ,
  831.                    DS:SI <-- buffer pointer
  832.                    DH,DL <-- upper left corner (row, column)
  833.  
  834.     SCRSAVE     save a screen area into a buffer                 ,  ,MV,  ,
  835.                    ES:DI <-- buffer pointer
  836.                    CH,CL <-- upper left corner (row, column)
  837.                    DH,DL <-- lower right corner (row, column)
  838.                    -------
  839.                       AX = bytes used to save screen area
  840.  
  841.     SHOWCURSOR  show the cursor                                BV,  ,MV,  ,
  842.  
  843.     STROUT      display a string                               BV,DV,MV,CG,HG
  844.                    DS:DX <-- pointer to ASCIIZ string
  845.  
  846.     WHERE       get the current cursor position                BV,  ,MV,CG,HG
  847.                    DH <-- row (1-25/43)
  848.                    DL <-- column (1-40/80/90)
  849.  
  850.                                 Video Services                          page 21
  851.  
  852.  
  853.  
  854. The ability to display graphics was once limited and very expensive, but this
  855. is no longer true.  PC-class computers have a wide variety of graphics
  856. standards to choose from.  This is useful whether you are interested in
  857. games, business charts, computer-aided design, icon-based mouse interfaces,
  858. or any number of other applications.  The ASMWIZ library provides numerous
  859. sets of graphics services which allow easy access to the capabilities of
  860. whatever display is installed.
  861.  
  862. The graphics services are divided into sets of routines, with each set of
  863. routines handling a specific video mode or modes.  This makes it possible to
  864. support just the modes you want, without extraneous code being linked in.
  865.  
  866. All graphics services are machine-level and demand hardware compatibility of
  867. both your computer and video adapter.  This is necessary because DOS doesn't
  868. support graphics at all, and the BIOS only supports very slow single-pixel
  869. handling.  If you are able to run standard graphics programs on your
  870. computer, however, you should experience no problems with these services.
  871.  
  872.                                 Video Services                          page 22
  873.  
  874.  
  875.  
  876. All of the graphics services share a common nomenclature and calling
  877. procedure.  The video mode is specified as a two-letter code prefix to the
  878. routine name, where the codes are as follows:
  879.  
  880.    Prefix    Mode(s)      Adapter    Resolution(s)      Colors
  881.    ------    --------     -------    ----------------   ------
  882.      G4        4, 5         CGA           320x200          4
  883.      G6          6          CGA           640x200          2
  884.      GD         13          EGA           320x200         16
  885.      GE       14, 16        EGA      640x200, 640x350     16
  886.      GH      Hercules       HGA           720x348          2
  887.  
  888. The service to display a line in Mode 6, for example, is named G6_LINE.
  889.  
  890. Provisions will be made in a future version of ASMWIZ for automatic handling
  891. of any available video mode, as well as conversion of images from one mode to
  892. another.
  893.  
  894.  
  895. The following services are available:
  896.  
  897.  
  898.     BOX         draw a box                                   GH,G4,G6,GD,GE
  899.                    CX <-- left X coordinate
  900.                    DX <-- top Y coordinate
  901.                    SI <-- right X coordinate
  902.                    DI <-- bottom Y coordinate
  903.                    AH <-- whether to fill box (0 no, 1 yes)
  904.                    AL <-- color
  905.  
  906.     GETPEL      get the current color of a point             GH,G4,G6
  907.                    CX <-- X coordinate
  908.                    DX <-- Y coordinate
  909.                    -------
  910.                    AL = color
  911.  
  912.     LINE        draw a line                                  GH,G4,G6,GD,GE
  913.                    CX <-- left X coordinate
  914.                    DX <-- top Y coordinate
  915.                    SI <-- right X coordinate
  916.                    DI <-- bottom Y coordinate
  917.                    AL <-- color
  918.  
  919.     PLOT        plot a point                                 GH,G4,G6,GD,GE
  920.                    CX <-- X coordinate
  921.                    DX <-- Y coordinate
  922.                    AL <-- color
  923.  
  924.                             Miscellaneous Services                      page 23
  925.  
  926.  
  927.  
  928. The Miscellaneous Services provide a number of services for various purposes,
  929. such as parsing the command line, determining the active video adapter,
  930. scanning the environment for a parameter, and generating pseudo-random
  931. numbers.  They eliminate much of the tedium of these common chores.
  932.  
  933.  
  934. The following services are available:
  935.  
  936.    MI_BOOT       reboot the computer (warm boot)
  937.  
  938.    MI_GETSCREEN  see what type of display is active
  939.                     -------
  940.                        AH = adapter type (1-6: MDA, Herc, CGA, EGA, MCGA, VGA)
  941.                        AL = color flag (0 color, 1 mono)
  942.  
  943.    MI_PARSE      parse a command line into filespecs and options
  944.                     DS:SI <-- ptr to command line (for COM files, = CS:0080h)
  945.                     ES:DI <-- ptr to filename buffer (recommend 128 bytes)
  946.                     ES:BX <-- ptr to option buffer (recommend 128 bytes)
  947.                        AL <-- switch character (normally "/" for MS-DOS)
  948.                     -------
  949.                        AH = number of options
  950.                        AL = number of filenames
  951.  
  952.    MI_RANDOM     generate a pseudo-random number
  953.                        DX <-- random number range (1-4000)
  954.                     -------
  955.                        AX = random number (0 to DX - 1)
  956.  
  957.    MI_RANDOMIZE  initialize the pseudo-random number generator
  958.                        AX <-- random number seed (use 0FFFFh for auto-seeding)
  959.  
  960.    MI_SCANENV    scan the DOS environment for a parameter
  961.                     DS:SI <-- ptr to the DOS environment or similar table
  962.                     ES:DI <-- ptr to the parm for which to search
  963.                     -------
  964.                        CY if not found
  965.                        NC if match found; DS:SI points to parm value
  966.  
  967.                                  Error Codes                            page 24
  968.  
  969.  
  970.  
  971. DOS error codes are returned by various of the DOS services, particularly the
  972. file and disk services.  The code is returned in the AL register.  This is a
  973. list of some of the possible errors.
  974.  
  975.  
  976.       2      file not found
  977.       3      path not found
  978.       4      too many open files (no handle available)
  979.       5      access denied
  980.       6      invalid handle
  981.       8      insufficient memory
  982.      15      invalid drive specified
  983.      16      tried to remove current directory
  984.      18      no more files
  985.  
  986.  
  987.  
  988.  
  989. Critical error codes are returned by the EH_CRITERR service in the AH
  990. register.  This is a list of the possible errors.
  991.  
  992.  
  993.       0      no critical error (if CY is set, it was a DOS error)
  994.       1      write-protected disk
  995.       2      unknown unit
  996.       3      drive not ready
  997.       4      unknown command
  998.       5      data/CRC error
  999.       6      bad request structure length
  1000.       7      seek error
  1001.       8      unknown media type
  1002.       9      sector not found
  1003.      10      printer out of paper
  1004.      11      write fault
  1005.      12      read fault
  1006.      13      general failure
  1007.      16      invalid disk change (only used by DOS 3.x and higher)
  1008.  
  1009.